"""
用户模块 - 信号处理
为用户管理功能提供自动化处理和事件响应
"""
from django.db.models.signals import post_save, pre_save
from django.dispatch import receiver
from django.contrib.auth import get_user_model

User = get_user_model()


@receiver(pre_save, sender=User)
def user_pre_save(sender, instance, **kwargs):
    """
    用户保存前的信号处理
    """
    # 可以在这里添加用户保存前的处理逻辑
    pass


@receiver(post_save, sender=User)
def user_post_save(sender, instance, created, **kwargs):
    """
    用户保存后的信号处理
    """
    if created:
        # 新用户创建时的处理逻辑
        print(f"新用户已创建: {instance.username}")
    else:
        # 用户更新时的处理逻辑
        pass


@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
    """
    创建用户资料
    """
    if created and not hasattr(instance, 'profile'):
        # 这里可以创建用户资料等关联对象
        pass